package com.appspot.kiyoshiro.kei3.model;

import java.io.Serializable;
import java.util.Date;

import com.google.appengine.api.datastore.Key;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;
import org.slim3.datastore.ModelRef;
//import org.slim3.datastore.CreationDate;
//import org.slim3.datastore.ModificationDate;

@Model(schemaVersion = 1)
public class User implements Serializable {

	public enum Role {
		NORMAL("normal"), MANAGER("manager");

		private String val;

		private Role(String val) {
			this.val = val;
		}

		public String val() {
			return this.val;
		}
	}

	private static final long serialVersionUID = 1L;

	@Attribute(primaryKey = true)
	private Key key;

	@Attribute(version = true)
	private Long version;

//	@Attribute(listener = CreationDate.class)
//	private Date createdAt;
//
//	@Attribute(listener = ModificationDate.class)
//	private Date updatedAt;

	private String account;

	private Role role;

	private boolean isApprove;

	private ModelRef<Table> tableRef = new ModelRef<Table>(Table.class);

//	/**
//	 * @param createdAt
//	 *            the createdAt to set
//	 */
//	public void setCreatedAt(Date createdAt) {
//		this.createdAt = createdAt;
//	}
//
//	/**
//	 * @return the createdAt
//	 */
//	public Date getCreatedAt() {
//		return createdAt;
//	}
//
//	/**
//	 * @param updatedAt
//	 *            the updatedAt to set
//	 */
//	public void setUpdatedAt(Date updatedAt) {
//		this.updatedAt = updatedAt;
//	}
//
//	/**
//	 * @return the updatedAt
//	 */
//	public Date getUpdatedAt() {
//		return updatedAt;
//	}

	/**
	 * Returns the key.
	 * 
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * Sets the key.
	 * 
	 * @param key
	 *            the key
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * Returns the version.
	 * 
	 * @return the version
	 */
	public Long getVersion() {
		return version;
	}

	/**
	 * Sets the version.
	 * 
	 * @param version
	 *            the version
	 */
	public void setVersion(Long version) {
		this.version = version;
	}

	/**
	 * @param account
	 *            the account to set
	 */
	public void setAccount(String account) {
		this.account = account;
	}

	/**
	 * @return the account
	 */
	public String getAccount() {
		return account;
	}

	/**
	 * @param role
	 *            the role to set
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	/**
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * @param isApprove
	 *            the isApprove to set
	 */
	public void setApprove(boolean isApprove) {
		this.isApprove = isApprove;
	}

	/**
	 * @return the isApprove
	 */
	public boolean isApprove() {
		return isApprove;
	}

	/**
	 * @return the tableRef
	 */
	public ModelRef<Table> getTableRef() {
		return tableRef;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		User other = (User) obj;
		if (key == null) {
			if (other.key != null) {
				return false;
			}
		} else if (!key.equals(other.key)) {
			return false;
		}
		return true;
	}
}
